home *** CD-ROM | disk | FTP | other *** search
- ; $Id: mystdvar.pro,v 1.9 1997/04/22 17:12:33 rob Exp $
- ;
- ; Copyright (c) 1997, Research Systems, Inc. All rights reserved.
- ; Unauthorized reproduction prohibited.
- ;+
- ; FILE:
- ; mystdvar.pro
- ;
- ; PURPOSE:
- ; This file contains an Analysis PlugIn that computes Standardized
- ; Variables of a 2D array.
- ;
- ; CONTENTS:
- ; GENERAL ROUTINES
- ; pro HandleEventsMyStdVar - handle dialog box events
- ;
- ; CALLBACK ROUTINES
- ; fun ApplyMyStdVar - Apply/OK entry point
- ; fun PromptUserMyStdVar - main entry point (creates dialog)
- ;
- ; REGISTRATION FUNCTION
- ; fun MyStdVar - registers the PlugIn
- ;
- ;-
-
- FORWARD_FUNCTION STANDARDIZE
-
- ; *****************************************************************************
- ; GENERAL ROUTINES
- ; *****************************************************************************
-
- ; -----------------------------------------------------------------------------
- ;
- ; Purpose: Handle dialog events.
- ;
- pro HandleEventsMyStdVar, sEvent
-
- ; Widget state information.
- ;
- common MyStdVarCommon, psState
- wGroup = (*psState).wMainBase
-
- ; Catch errors.
- ;
- CATCH, error
- if (error ne 0) then begin
- CATCH, /CANCEL
- void = DIALOG_MESSAGE(!ERR_STRING, DIALOG_PARENT=wGroup)
- RETURN
- endif
-
- ; ========================
- ; PROCESS EVENTS
- ; ========================
-
- case (sEvent.id) of
-
- ; --------------------------------------
- ; Input text
- ; --------------------------------------
- (*psState).wInputText: begin
-
- ; (nothing to do now)
-
- end
-
- ; --------------------------------------
- ; Input browse button
- ; --------------------------------------
- (*psState).wInputBrowseButton: begin
-
- ; Let user browser for a data name.
- ;
- void = INSGET( $
- NAME=inputName, $ ; returned name of data selected
- /EXCLUSIVE, $ ; only one selection
- TITLE='Select an array.', $ ; title of browser
- DIMS_LIST=2, $ ; show 2D array data only
- COUNT=count, $ ; returned count of items selected
- GROUP=wGroup, $ ; widget group leader
- _EXTRA=(*psState).extra) ; extra information
-
- ; If user selected an item, set data name in text widget.
- ;
- if (count eq 1) then $
- WIDGET_CONTROL, (*psState).wInputText, SET_VALUE=inputName
-
- end
-
- ; --------------------------------------
- ; Std. Variables (column or row) bgroup
- ; --------------------------------------
- (*psState).wStdVarBgroup: begin
-
- WIDGET_CONTROL, (*psState).wStdVarBgroup, GET_VALUE=value
-
- if (value eq 0) then $
- (*psState).StdVarOrient = 0 $
- else if (value eq 1) then $
- (*psState).StdVarOrient = 1
-
- end
-
- ; --------------------------------------
- ; OK/Apply/Cancel buttons
- ; --------------------------------------
- (*psState).wOKApplyCancelButtons: begin
-
- ; Destroy dialog on successful OK selection, or if user canceled.
- ;
- if ((sEvent.type eq 'OK') or $
- (sEvent.type eq 'Cancel')) then $
- WIDGET_CONTROL, (*psState).wMainBase, /DESTROY
- end
-
- ; --------------------------------------
- ; other events
- ; --------------------------------------
- else: ; (do nothing)
-
- endcase
-
- end ; HandleEventsMyStdVar
-
- ; *****************************************************************************
- ; CALLBACK ROUTINES
- ; *****************************************************************************
-
- ; -----------------------------------------------------------------------------
- ;
- ; Purpose: Get data and StdVar it.
- ; Fuction returns 1B on success, else 0B.
- ;
- function ApplyMyStdVar, $
- CIDs=CIDs, $ ; OUT: command ID list from INSPUT/INSVIS calls
- _EXTRA=extra ; IN: information to pass to commands
-
- ; Widget state information.
- ;
- common MyStdVarCommon, psState
- wGroup = (*psState).wMainBase
-
- ; ---------------------------------------------------------
- ; Catch errors.
- ; ---------------------------------------------------------
-
- CATCH, error
- if (error ne 0) then begin
- CATCH, /CANCEL
- void = DIALOG_MESSAGE(!ERR_STRING, DIALOG_PARENT=wGroup)
- RETURN, 0B
- endif
-
- ; ---------------------------------------------------------
- ; Check inputs.
- ; ---------------------------------------------------------
-
- ; Get and check input data name.
- ;
- WIDGET_CONTROL, (*psState).wInputText, GET_VALUE=inputName
- inputName = inputName[0]
- if (inputName eq '') then $
- MESSAGE, 'Must specify input data.'
-
- ; Get input data.
- ;
- inputData = INSGET( $
- inputName, $ ; name of data to get
- COUNT=count, $ ; returned number of items found
- DIMS_LIST=2, $ ; data should have this dimensionality
- GROUP=wGroup, $ ; widget group leader
- _EXTRA=extra) ; extra information
-
- ; Return if data not found (INSGET displays own error messages).
- ;
- if (count ne 1) then $
- RETURN, 0B
-
- ; ---------------------------------------------------------
- ; Compute Standardized Variables.
- ; ---------------------------------------------------------
-
- if ((*psState).StdVarOrient eq 0) then $ ; Standardize by column.
- newData = STANDARDIZE(inputData) $
- else $ ; Standardize by row.
- newData = TRANSPOSE(STANDARDIZE(TRANSPOSE(inputData)))
-
- ; ---------------------------------------------------------
- ; Put the new data into Insight (Data Manager)
- ; ---------------------------------------------------------
-
- description = 'Standardized ' + inputName
-
- outputName = (*psState).outputName
-
- INSPUT, $
- newData, $ ; the data
- DESCRIPTION=description, $ ; data description
- NAME=outputName, $ ; try this data name
- NEW_NAME=outputNameUsed, $ ; the data name actually used
- REPLACE=2, $ ; prompt user if name conflict
- COUNT=count, $ ; returned # of items put
- CIDs=CIDs, $ ; command ID list
- GROUP=wGroup, $ ; widget group leader
- _EXTRA=extra ; extra information
-
- ; Return if "put" failed.
- ;
- if (count ne 1) then $
- RETURN, 0B
-
- ; ---------------------------------------------------------
- ; Visualize new data item.
- ; ---------------------------------------------------------
-
- INSVIS, $
- outputNameUsed, $ ; name of data item
- TYPE='surface', $ ; visualization type
- MODE='new', $ ; insert | new | overlay
- CIDs=CIDs, $ ; command ID list
- GROUP=wGroup, $ ; widget group leader
- _EXTRA=extra ; extra information
-
- ; ---------------------------------------------------------
- ; Successful return.
- ; ---------------------------------------------------------
-
- RETURN, 1B
-
- end ; ApplyMyStdVar
-
- ; -----------------------------------------------------------------------------
- ;
- ; Purpose: Main entry point for the PlugIn.
- ;
- pro PromptUserMyStdVar, $
- GROUP=wGroup, $ ; IN: group leader widget ID
- _EXTRA=extra ; IN: various information
-
- ; Widget state information.
- ;
- common MyStdVarCommon, psState
-
- ; Create modal main base (non-sizable).
- ;
- title = 'Analysis PlugIn - Standardized Variables'
- wMainBase = WIDGET_BASE(TITLE=title, GROUP_LEADER=wGroup, $
- /COLUMN, /MODAL, /TLB_FRAME_ATTR)
-
- value = [ $
- 'Select a 2D array to compute Standardized Variables.', $
- 'Standardized Variables are a prerequisite to most', $
- 'types of multivariate statistical analysis.', $
- 'Output is displayed as a surface and is available', $
- 'through the Data Manager.' $
- ]
- for i = 0, N_ELEMENTS(value)-1 do $
- void = WIDGET_LABEL(wMainBase, VALUE=value[i])
-
- ; ------------------------------------------
- ; Create INPUTS widgets.
- ; ------------------------------------------
-
- wInputsBase = WIDGET_BASE(wMainBase, /COLUMN, /FRAME)
-
- void = WIDGET_LABEL(wInputsBase, VALUE='INPUTS')
-
- wInputDataBase = WIDGET_BASE(wInputsBase, /ROW)
- void = WIDGET_LABEL(wInputDataBase, VALUE='Input: ')
- wInputText = WIDGET_TEXT(wInputDataBase, VALUE='', /EDITABLE)
- wInputBrowseButton = WIDGET_BUTTON(wInputDataBase, VALUE=' Browse... ')
-
- wStdVarBase = WIDGET_BASE(wInputsBase, /ROW)
- void = WIDGET_LABEL(wStdVarBase, VALUE='Orientation: ')
- wStdVarBgroup = CW_BGROUP(wStdVarBase, ['By Column', 'By Row'], $
- /NO_RELEASE, /ROW, /RETURN_NAME, /EXCLUSIVE, SET_VALUE=0)
- StdVarOrient = 0
-
- ; ------------------------------------------
- ; Create OUTPUTS widgets.
- ; ------------------------------------------
-
- outputName = 'Standardized Output'
-
- wOutputsBase = WIDGET_BASE(wMainBase, /ROW, /FRAME)
- void = WIDGET_LABEL(wOutputsBase, VALUE=' ')
-
- wOutputsLabelBase = WIDGET_BASE(wOutputsBase, /COLUMN)
- void = WIDGET_LABEL(wOutputsLabelBase, VALUE='OUTPUTS')
- void = WIDGET_LABEL(wOutputsLabelBase, VALUE='Output: '+outputName)
-
- ; ------------------------------------------
-
- ; Create OK/Apply/Cancel buttons using special compound widget.
- ; (Must pass in main modal base, used to set default and cancel buttons.)
- ;
- wOKApplyCancelButtons = CW_INSAPPLY(wMainBase, _EXTRA=extra)
-
- ; Create dialog state information.
- ;
- sState = { $
- extra: extra, $
- wMainBase: wMainBase, $
- outputName: outputName, $
- wInputText: wInputText, $
- wInputBrowseButton: wInputBrowseButton, $
- wStdVarBgroup: wStdVarBgroup, $
- StdVarOrient: StdVarOrient, $
- wOKApplyCancelButtons: wOKApplyCancelButtons $
- }
-
- ; Store the state in a heap variable.
- ;
- psState = PTR_NEW(sState, /NO_COPY)
-
- ; Realize the dialog box.
- ;
- WIDGET_CONTROL, wMainBase, /REALIZE
-
- ; Start event loop.
- ;
- XMANAGER, 'PromptUserMyStdVar', wMainBase, $
- EVENT_HANDLER='HandleEventsMyStdVar'
-
- ; Remove widget state info.
- ;
- PTR_FREE, psState
-
- end ; PromptUserMyStdVar
-
- ; *****************************************************************************
- ; REGISTRATION FUNCTION
- ; *****************************************************************************
-
- ; -----------------------------------------------------------------------------
- ;
- ; Purpose: Register the Analysis PlugIn.
- ;
- function MyStdVar
-
- ; Return the Analysis PlugIn Registration Structure.
- ;
- RETURN, { $
- type: 'Analysis_PlugIn', $ ; PlugIn type
- title: 'My StdVar...', $ ; PlugIn title
- purpose: 'Compute standardized variables.', $ ; PlugIn purpose
- main_proc: 'PromptUserMyStdVar', $ ; main callback
- apply_func: 'ApplyMyStdVar', $ ; apply callback
- version: '5.0', $ ; IDL version
- revision: '1.0' $ ; PlugIn version
- }
-
- end ; MyStdVar
-
- ; -----------------------------------------------------------------------------
-